/**
 * Definition for singly-linked list.
 * struct ListNode {
 *     int val;
 *     ListNode *next;
 *     ListNode(int x) : val(x), next(NULL) {}
 * };
 */
class Solution {
public:
    ListNode* deleteNode(ListNode* head, int val) {
        //在O(n)的时间内，顺序查找结点值为val的指针
        if(!head)  return head;
        if(head->val == val)  return head->next;

        ListNode* pNode = head;
        //迭代，依次判断各个节点的下一个结点
        while(pNode->next){
            if(pNode->next->val == val){
                pNode->next = pNode->next->next;  //删除链表结点
                break;
            }
            pNode = pNode->next;  //1刷时漏掉该式出现死循环
        }
        return head;
    }
};